import TileLayer from 'ol/layer/Tile'
import WMTS from 'ol/source/WMTS' // eslint-disable-line
import TileWMS from 'ol/source/TileWMS' // eslint-disable-line
import XYZ from "ol/source/XYZ";
import TileArcGISRest from "ol/source/TileArcGISRest";
import TileImage from "ol/source/TileImage";
import Source from "ol/source/Source"; // eslint-disable-line
import TileGrid from 'ol/tilegrid/TileGrid'; // eslint-disable-line
import VectorSource from 'ol/source/Vector';
import ImageStatic from 'ol/source/ImageStatic';
import VectorLayer from "ol/layer/Vector";
import ImageLayer from 'ol/layer/Image';
import ImageWMS from 'ol/source/ImageWMS';
import Cluster from 'ol/source/Cluster';
import WMTSTileGrid from "ol/tilegrid/WMTS";
import {Fill, Stroke, Style, Circle as circleStyle} from 'ol/style';
import {fromLonLat, get as getProjection} from "ol/proj";
import {getTopLeft, getWidth} from "ol/extent";
import {Draw, Modify, Snap} from 'ol/interaction';// eslint-disable-line
import olTilegrid from 'ol/tilegrid/TileGrid';
import {get as Proj} from 'ol/proj'
import Feature from "ol/Feature";
import Circle from "ol/geom/Circle";
import Polygon from "ol/geom/Polygon";
import Point from "ol/geom/Point";
import GeoJSON from "ol/format/GeoJSON";
import Icon from "ol/style/Icon";
import Text from "ol/style/Text";

function Layer(map) {
    this.map = map;
}

/**
 * 添加雷达图/卫星云图
 */
Layer.prototype.addRadar = function (url, layerName) {
    let layer = new TileLayer({
        // visible: true,
        visible: false,
        source: new TileWMS({
            ratio: 1,
            url,
            params: {
                STYLES: '',
                LAYERS: layerName
            },
            projection: "EPSG:4326",
        }),
    });
    this.map.addLayer(layer)
    return layer;
}

Layer.prototype.drawCircle = function (radius, center = [], style, layer) {
    center = [parseFloat(center[0]), parseFloat(center[1])];
    let metersPerUnit = this.map.getView().getProjection().getMetersPerUnit();
    let circleRadius = radius / metersPerUnit;
    let circle = new Circle(center, circleRadius);
    // let polygon = new Polygon.fromCircle(circle);//转换为polygon，用于空间查询
    let circleFeature = new Feature({
        geometry: circle,
    });
    style = style || new Style({
        fill: new Fill({color: "rgba(255,0,0,0.5)"}),
        stroke: new Stroke({width: 1, color: 'red',})
    })
    circleFeature.setStyle(style);
    layer.getSource().addFeature(circleFeature);
}

/**
 *
 * @param radius
 * @param center
 * @param style
 * @param layer
 * @param text
 */
Layer.prototype.addPoint = function (radius, center = [], color, layer) {
    center = [parseFloat(center[0]), parseFloat(center[1])];
    let pointFeature = new Feature({
        geometry: new Point(center),
    });
    let style = {
        fill: new Fill({color: color || "rgba(255,255,0,0.5)",}),
        stroke: new Stroke({
            color: color || "rgba(255,255,0,0.5)",
            size: 1,
        }),
    }
    style.radius = radius;
    style = new Style({
        image: new circleStyle(style),
    })
    pointFeature.setStyle(style);
    layer.getSource().addFeature(pointFeature);
}

/**
 * 图标文字打点
 * */
Layer.prototype.drawPoint = function (coord = [], src, layer, text, offset, color, attr) {
    coord = [parseFloat(coord[0]), parseFloat(coord[1])];
    let pointFeature = new Feature({
        geometry: new Point(coord),
    });

    let style = new Style({
        image: new Icon({
            scale: 0.2,
            src,
            anchor: [0.48, 0.52]
        }),
        text: new Text({
            font: 'normal 12px 黑体',
            //  对齐方式
            textAlign: 'center',
            // 基准线
            textBaseline: 'middle',
            offsetY: offset[0] || -15,
            offsetX: offset[1] || 0,
            backgroundFill: new Stroke({
                color: color[1] || 'rgba(255,255,255,0)',
            }),
            // 文本填充样式
            fill: new Fill({
                color: color[0] || 'white'
            }),
            text,
        }),
    })
    if (attr) {
        attr.coord = coord;
        pointFeature.setProperties(attr);
    }
    pointFeature.setStyle(style);
    layer.getSource().addFeature(pointFeature);
}

/**
 * @description: 叠加高德地图
 * @param {*}
 * @return {*} 图层对象
 */
Layer.prototype.addGaodeMapLayer = function () {
    const gaodeLayer = new TileLayer({
        source: new XYZ({
            url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}'
        })
    });

    const layersArray = this.map.getLayers();
    layersArray.insertAt(0, gaodeLayer);
    // this.map.addLayer(gaodeLayer);
    return gaodeLayer;
}

Layer.prototype.drawGeoJSON = function (jsonData, color, layer, projection, attr) {
    let feature = new GeoJSON({featureProjection: projection || 'EPSG:4326'}).readFeature(jsonData);
    color = color || 'rgba(234,28,39,0.8)';
    let style = new Style({
        fill: new Fill({color,}),
        stroke: new Stroke({color, width: 1}),
    })
    feature.setStyle(style)
    if (attr)
        feature.setProperties(attr)
    layer.getSource().addFeature(feature);
}

/**
 * @description: 叠加高德地图实时路况图层
 * @param {*}
 * @return {*} 图层对象
 */
Layer.prototype.addGaodeTrafficMapLayer = function () {
    const gaodeLayer = new TileLayer({
        source: new XYZ({
            url: 'http://tm.amap.com/trafficengine/mapabc/traffictile?v=1.0&x={x}&y={y}&z={z}&&t=longTime',
            tileUrlFunction: function (tileCoord) {
                const z = tileCoord[0];
                const x = Math.abs(tileCoord[1]);
                const y = Math.abs(tileCoord[2]);
                const longTime = new Date().getTime();

                let urlNow = 'http://tm.amap.com/trafficengine/mapabc/traffictile?v=1.0&x={x}&y={y}&z={z}&&t=longTime';
                urlNow = urlNow.replace('{z}', z);
                urlNow = urlNow.replace('{y}', y);
                urlNow = urlNow.replace('{x}', x);
                urlNow = urlNow.replace('longTime', longTime);
                return urlNow;
            }
        })
    });
    this.map.addLayer(gaodeLayer);
    return gaodeLayer;
}

/**
 * @description: 叠加谷歌影像地图
 * @param {*}
 * @return {*} 图层对象
 */
Layer.prototype.addGoogleImageLayer = function () {
    // https://www.google.cn/maps/vt?lyrs=s@804&gl=cn&x=101&y=51&z=7
    const googleLayer = new TileLayer({
        source: new XYZ({
            url: 'http://ditu.google.cn/maps/vt?lyrs=s@804&gl=cn&x={x}&y={y}&z={z}',
            projection: 'EPSG:3857'
        }) //加载谷歌影像地图
    });
    const layersArray = this.map.getLayers();
    layersArray.insertAt(0, googleLayer);
    // this.map.addLayer(googleLayer);
    return googleLayer;
}

/**
 * @description: 叠加谷歌离线地图
 * @param {*}
 * @return {*} 图层对象
 */
Layer.prototype.addUnderLineGoogleImageLayer = function () {
    /*定义谷歌地球分辨率与瓦片网格*/
    var maxResolution = 180.0 / 256;
    var resolutions = [];
    for (var i = 1; i <= 20; i++) {
        resolutions[i] = Math.pow(2, 1 - i) * maxResolution;
    }

    var tilegrid = new olTilegrid({
        // extent:[-180,-90,180,90],
        origin: [-464.7383, -206.30749],
        resolutions: resolutions
    });

    /*加载谷歌地球瓦片不能用ol.source.XYZ，ol.source.XYZ针对谷歌地图（注意：是谷歌地图）而设计，
              而谷歌地球与谷歌地图用不同的投影、分辨率和瓦片网格。因此这里使用ol.source.TileImage来自行指定
              投影、分辨率、瓦片网格。*/
    var source = new TileImage({
        tileGrid: tilegrid,
        tileUrlFunction: function (tileCoord) {
            var z = tileCoord[0];
            var x = tileCoord[1];
            /*由于OpenLayers5依然没有提供定义瓦片网格编号在X/Y轴上增长方向的入口.
                          这里用了个小技巧来明确这一信息。*/
            var y = -tileCoord[2] - 1;

            return 'static/mapsWorld_tiles/' + z + '/' + x + '/' + y + '.png';
        }
    });

    const sffLineMap = new TileLayer({
        source: source
    });
    this.map.addLayer(sffLineMap);
    return sffLineMap;
}


/**
 * @description: 叠加天地图影像图
 * @param {boolean} showZj 是否显示注记图层,默认为true显示
 * @return {*} 图层对象
 */
Layer.prototype.addTianDiTuImgLayer = function (showZj = true) {
    const webKey = '72284c0833cc77096d5c6f1e5a45eff8';
    const imgLayerUrl_dt = 'http://t{0-7}.tianditu.gov.cn/DataServer?T=img_c&X={x}&Y={y}&L={z}&tk='; //影像底图
    const imgLayerUrl_zj = 'http://t{0-7}.tianditu.gov.cn/DataServer?T=cia_c&X={x}&Y={y}&L={z}&tk='; //影像注记
    const layerDt = new TileLayer({
        source: new XYZ({
            url: imgLayerUrl_dt + webKey,
            wrapX: false,
            projection: 'EPSG:4326',
            crossOrigin: 'anonymous',
        })
    });
    this.map.addLayer(layerDt);
    if (showZj) {
        const layerZj = new TileLayer({
            source: new XYZ({
                url: imgLayerUrl_zj + webKey,
                wrapX: false,
                projection: 'EPSG:4326',
                crossOrigin: 'anonymous',
            })
        });
        this.map.addLayer(layerZj);
        return [layerDt, layerZj];
    } else {
        return layerDt;
    }
};

/**
 * @description: 叠加天地图矢量图
 * @param {boolean} showZj 是否显示注记图层,默认为true显示
 * @return {*} 图层对象
 */
Layer.prototype.addTianDiTuVecLayer = function (showZj = true) {
    const webKey = '72284c0833cc77096d5c6f1e5a45eff8';
    const imgLayerUrl_dt = 'http://t{0-7}.tianditu.gov.cn/DataServer?T=vec_c&X={x}&Y={y}&L={z}&tk='; //矢量底图
    const imgLayerUrl_zj = 'http://t{0-7}.tianditu.gov.cn/DataServer?T=cva_c&X={x}&Y={y}&L={z}&tk='; //矢量注记
    const layerDt = new TileLayer({
        source: new XYZ({
            url: imgLayerUrl_dt + webKey,
            wrapX: false,
            projection: 'EPSG:4326',
            crossOrigin: 'anonymous',
        })
    });
    this.map.addLayer(layerDt);
    if (showZj) {
        const layerZj = new TileLayer({
            source: new XYZ({
                url: imgLayerUrl_zj + webKey,
                wrapX: false,
                projection: 'EPSG:4326',
                crossOrigin: 'anonymous',
            })
        });
        this.map.addLayer(layerZj);
        return [layerDt, layerZj];
    } else {
        return layerDt;
    }
};

/**
 * @description: 添加天地图地形图
 * @param {boolean} showZj 是否显示注记图层,默认为true显示
 * @return {*} 图层对象
 */
Layer.prototype.addTianDiTuTerLayer = function (showZj = true) {
    const webKey = '72284c0833cc77096d5c6f1e5a45eff8';
    const imgLayerUrl_dt = 'http://t{0-7}.tianditu.gov.cn/DataServer?T=ter_c&X={x}&Y={y}&L={z}&tk='; //地形底图
    const imgLayerUrl_zj = 'http://t{0-7}.tianditu.gov.cn/DataServer?T=cta_c&X={x}&Y={y}&L={z}&tk='; //地形注记
    const layerDt = new TileLayer({
        source: new XYZ({
            url: imgLayerUrl_dt + webKey,
            wrapX: false,
            projection: 'EPSG:4326',
            crossOrigin: 'anonymous',
        })
    });
    this.map.addLayer(layerDt);
    if (showZj) {
        const layerZj = new TileLayer({
            source: new XYZ({
                url: imgLayerUrl_zj + webKey,
                wrapX: false,
                projection: 'EPSG:4326',
                crossOrigin: 'anonymous',
            })
        });
        this.map.addLayer(layerZj);
        return [layerDt, layerZj];
    } else {
        return layerDt;
    }
};

/**
 * @description: 添加XYZ形式的瓦片图层
 * @param {string} url 图层路径
 * @param {string} proj 坐标系，默认EPSG:4326
 * @return {*} 图层对象
 */
Layer.prototype.addXYZTileLayer = function (url, proj) {
    //'http://103.3.152.231:9312/Tiles/520200_InSAR_Faer/{x}/{y}/{z}.png'
    const layerTile = new TileLayer({
        source: new XYZ({
            url: url,
            wrapX: false,
            projection: proj || 'EPSG:4326'
        })
    });
    this.map.addLayer(layerTile);
    return layerTile;
};


/**
 * @description: 添加arcgis瓦片服务图层
 * @param {string} layerName 图层路径名称
 * @param {string} url 图层路径
 * @return {TileLayer} 图层对象
 */
Layer.prototype.addArcgisMapServer = function (layerName, url) {
    if (url) {
        const arcLayer = new TileLayer({
            source: new TileArcGISRest({
                wrapX: false,
                url: url
            })
        })
        this.map.addLayer(arcLayer);
        if (layerName) {
            arcLayer.set('layerName', layerName);
        }
        return arcLayer
    }
}

/**
 * @description: 根据图层名获取图层
 * @param {string} layerName 图层名称
 * @return {*} 对应图层对象
 */
Layer.prototype.getLayerByName = function (layerName) {
    let layerArr = this.map.getLayers().array_;
    for (let k = 0; k < layerArr.length; k++) {
        if (layerArr[k].values_.layerName == layerName || layerArr[k].layerName == layerName) {
            return layerArr[k];
        }
    }
}

Layer.prototype.removeLayer = function (layer) {
    this.map.removeLayer(layer)
}




Layer.prototype.addLayer = function (layer) {
    this.map.addLayer(layer)
}
/**
 * 叠加静态图片
 * @param extent 图片坐标范围
 * @url  图片源
 */
Layer.prototype.addStaticImage = function (extent, url, opacity, projection) {
    // console.log("url",url)
    let imageSource = new ImageStatic({
        url: url,
        projection: projection || Proj('EPSG:4326'),
        crossOrigin: '',
        imageExtent: extent
    });
    let imageLayer = new ImageLayer({
        source: imageSource,
        opacity: opacity || 0.8,
        zIndex: 99,
    });
    this.map.addLayer(imageLayer);
    imageLayer.setVisible(false);
    return imageLayer;
}

Layer.prototype.getImg = function (leftBottom, rightTop,) {
    let canvas, resultCanvas;
    this.map.once('postcompose', (event) => {
        canvas = event;
        console.log("canvas.context", event.context)
        let leftBottomPixel = this.map.getPixelFromCoordinate(leftBottom);
        let rightTopPixel = this.map.getPixelFromCoordinate(rightTop);
        let ctx = canvas.getContext('2d');
        let origin = [leftBottomPixel[0], rightTopPixel[1]],
            originWidth = rightTopPixel[0] - leftBottomPixel[0],
            originHeight = leftBottomPixel[1] - rightTopPixel[1];
        let imgData = ctx.getImageData(origin[0], origin[1], originWidth, originHeight);
        // resultCanvas=document.getElementById('resultCanvas');
        // resultCanvas.width=originWidth;
        // resultCanvas.height=originHeight;
        // let resultCtx=resultCanvas.getContext('2d');
        // resultCtx.putImageData(imgData,0,0);
        console.log("imgData", imgData)
    })
    map.render();
}

/**
 * @description: 创建矢量图层
 * @param {string} layerName 图层名称
 * @param {object} styleObj 样式,非必传
 * @param {int} zIndex 叠层顺序,非必传
 * @return {*} 图层对象
 */
let timeId = null;
Layer.prototype.createVectorLayer = function (layerName, styleObj, zIndex, sourceObj, declutter) {
    // if (timeId)
    //     clearTimeout(timeId);
    let _sourceObj = sourceObj == null ? {wrapX: false} : sourceObj
    let source = new VectorSource(_sourceObj);
    let vectorLayer = new VectorLayer({
        source: source,
        zIndex: zIndex || 10,
        declutter: declutter || false,//防止标注文字重复标注
        style: styleFunction(styleObj)
    });
    vectorLayer.set('layerName', layerName);
    // timeId = setTimeout(() => {
    this.map.addLayer(vectorLayer);
    // }, 1000)
    return vectorLayer;
}

/**
 * 创建聚合图层
 * @returns {VectorLayer<VectorSourceType>}
 */
Layer.prototype.createClusterLayer = function (layerName, zIndex, source) {
    let clusterSource = new Cluster({
        source,
        distance: 100,
    })

    let clusterLayer = new VectorLayer({
        source: clusterSource,
        zIndex: zIndex || 10,
        style: function (feature, resolution) {
            var size = feature.get('features').length;
            if (size == 1) {
                return new Style({
                    image: new Icon({
                        src: '@/assets/image/图标/减灾能力图标/避难场所.png'
                    })
                })
            } else {
                return new Style({
                    image: new circleStyle({
                        radius: 15,
                        stroke: new Stroke({
                            color: 'white'
                        }),
                        fill: new Fill({
                            color: 'blue'
                        })
                    }),
                    text: new Text({
                        text: size.toString(),
                        fill: new Fill({
                            color: 'white'
                        })
                    })
                })
            }
        }
    });
    clusterLayer.set('layerName', layerName);
    this.map.addLayer(clusterLayer);
    return clusterLayer;
}
/**
 * 添加聚合点
 * @param center 点的坐标
 * @param source 矢量图层数据源
 */
Layer.prototype.addClusterPoint = function (center = [], source) {
    let coordinates = [parseFloat(center[0]), parseFloat(center[1])];
    let pointFeature = new Feature(new Point(coordinates));
    source.addFeature(pointFeature);
}

Layer.prototype.createVectorSource = function () {
    return new VectorSource();
}

Layer.prototype.createMaskLayer = function (layerName, styleObj, zIndex, sourceObj, declutter) {
    let _sourceObj = sourceObj == null ? {wrapX: false} : sourceObj
    let source = new VectorSource(_sourceObj);
    let vectorLayer = new VectorLayer({
        source: source,
        zIndex: zIndex || 10,
        declutter: declutter || false,//防止标注文字重复标注
        style: styleFunction(styleObj)
    });
    vectorLayer.set('layerName', layerName);
    this.map.addLayer(vectorLayer);
    return vectorLayer;
}

/**
 * @description: 创建图片图层
 * @param {string} layerName 图层名称
 * @param {string} url 图片路径
 * @param {array} extent 图片范围
 * @param {object} styleObj 样式,非必传
 * @return {ImageLayer} 图片对象
 */
Layer.prototype.createImageLayer = function (layerName, url, extent, styleObj) {
    let source = new ImageStatic({
        url: url,//地址
        imageExtent: extent
    });
    let imageLayer = new ImageLayer({
        source: source,
        zIndex: 10,
        style: styleFunction(styleObj)
    });
    imageLayer.set('layerName', layerName);
    this.map.addLayer(imageLayer);
    return imageLayer;
}

/**
 * @description: 根据gdbp地址叠加mapgis图层
 * @param {string} gisUrl gis服务器地址，如http://127.0.0.1:6163/
 * @param {array} gdbps 多个图层的gdbp地址
 * @param {string} layerName 图层名称
 * @return {*} 图层对象
 */
Layer.prototype.addMapgisGdbpsLayer = function (gisUrl, gdbps, layerName) {
    let url = gisUrl + 'igs/rest/mrms/layers?f=png';
    let params = {
        'f': 'png',
        'gdbps': gdbps.join(','),
        'VERSION': '1.1.0',
        'rlt': Math.random()
    }
    var wmsSource = new ImageWMS({
        projection: 'EPSG:4326',
        url: url.split('?')[0],
        params: params,
        serverType: 'geoserver',
        crossOrigin: 'anonymous',
        imageLoadFunction: function (image, src) {
            image.getImage().src = src.replace('WIDTH', 'w').replace('HEIGHT', 'h');
        }
    });
    var imageLayer = new ImageLayer({
        source: wmsSource
    });
    imageLayer.set('layerName', layerName);
    this.map.addLayer(imageLayer);
    return imageLayer;
}


/**
 * @description: 叠加geoserver发布的矢量地图
 * @param {string} layerName 图层名称
 * @param {string} url 图层路径
 * @param {object} params 参数
 * @return {ImageLayer} 图层对象
 */
Layer.prototype.addGeoServerWmsLayer = function (layerName, url, params) {
    // let url='http://61.243.4.40:5029/geoserver/guizhou/wms?service=WMS&version=1.1.0&request=GetMap&layers=guizhou%3Ademo&bbox=103.571142526%2C24.55770449%2C109.644772231%2C29.243289098&width=768&height=592&srs=EPSG%3A4326&format=application/openlayers';
    if (!url) return null;
    url = decodeURIComponent(url);
    //如果参数为空，则从路径中截取相关参数，如果不为空，则使用传过来的参数
    if (!params) {
        let paramObj = getUrlParams(url);
        console.log('执行')
        params = {
            'VERSION': paramObj.version || '1.1.0',
            'LAYERS': paramObj.layers,
            'SRS': paramObj.srs,
            'FORMAT': 'image/png',
            'exceptions': 'application/vnd.ogc.se_inimage',
            "width": paramObj.width,
            "height":paramObj.height
        }
    }
    var wmsSource = new ImageWMS({
        projection: 'EPSG:4326',
        url: url.split('?')[0],
        params: params,
        serverType: 'geoserver',
        crossOrigin: 'anonymous',
    });
    var wmsLayer = new ImageLayer({
        source: wmsSource,
        zIndex: 100,
    });
    this.map.addLayer(wmsLayer);
    return wmsLayer;
};

/**
 * @description: 叠加geoserver发布的瓦片地图
 * @param {string} layerName 图层名称
 * @param {string} url 图层路径
 * @param {object} params 参数
 * @return {ImageLayer} 图层对象
 */
Layer.prototype.getGeoServerWmtsLayer = function (layerName, url, type) {
    // let url='http://61.243.4.40:5029/geoserver/guizhou/wms?service=WMS&version=1.1.0&request=GetMap&layers=guizhou%3Ademo&bbox=103.571142526%2C24.55770449%2C109.644772231%2C29.243289098&width=768&height=592&srs=EPSG%3A4326&format=application/openlayers';
    if (!url) return null;
    url = decodeURIComponent(url);
    // baseLayers = {
    //   '全国二维影像(0.27 米)服务': kdLayer,
    //   '全国二维矢量地图服务': vecLayer,
    //   '全国二维地形地图服务': terLayer
    //  };
    //  overLayers = {
    //   '全国二维影像注记服务': ciaLayer,
    //   '全国二维影像地图行政区划服务': iboLayer,
    //   '全国二维矢量注记服务': cvaLayer,
    //   '全国二维地形注记服务': ctaLayer,
    //   '全国二维地形地图行政区划服务': tboLayer
    //  };

    const projection = getProjection("EPSG:4326");
    const projectionExtent = projection.getExtent();
    const size = getWidth(projectionExtent) / 256;
    const resolutions1 = new Array(19);
    const resolutions = new Array(19);
    const matrixIds = new Array(19);
    for (let z = 0; z < 20; ++z) {
        //1.40625
        resolutions1[z] = size / Math.pow(2, z); //天地图经纬 度底图的计算参数
        resolutions[z] = 1.40625285 / Math.pow(2, z); //苍穹 底图计算参数（可能需要修改，根据点位偏移自己去调整）
        matrixIds[z] = z;
    }
    let layer =
        new TileLayer({
            source: new WMTS({
                name: layerName,
                url: url,
                layer: type,
                style: "default",
                matrixSet: "c",
                format: "tiles",
                wrapX: true,
                tileGrid: new WMTSTileGrid({
                    origin: getTopLeft(projectionExtent), //resolutions: res.slice(0, 15),
                    resolutions: resolutions,
                    matrixIds: matrixIds,
                }),
            }),
        })
    // console.log(1,layer)
    this.map.addLayer(layer)
    return layer;
}
/**
 * @description: 将url中的参数转为对象
 * @param {string} url 地址
 * @return {object} 参数对象
 */
var getUrlParams = function (url) {
    var tmparray = url.split("?")[1].split("&");
    var paramsArray = {};
    if (tmparray != null) {
        for (var i = 0; i < tmparray.length; i++) {
            var reg = /[=|^==]/;  // 用=进行拆分，但不包括==
            var set1 = tmparray[i].replace(reg, '&');
            var tmpStr2 = set1.split('&');
            paramsArray[tmpStr2[0]] = tmpStr2[1];
        }
    }
    return paramsArray;
}

/**
 * @description: 设置图层样式
 * @param {object} styleObj
 * {
 *  strokeColor:'rgba(255,0,0,0.2)',边线颜色
 *  strokeWidth:2, 边线宽度
 *  fillColor:'rgba(255,0,0,0.2)' 填充颜色
 * }
 * @return {Style} 样式对象
 */
var styleFunction = function (styleObj) {
    let style = {};
    if (styleObj && (styleObj.strokeColor || styleObj.strokeWidth)) {
        style.stroke = new Stroke({
            color: styleObj.strokeColor || 'rgba(255,0,0,0.2)',
            width: styleObj.strokeWidth || 1
        });
    }
    if (styleObj && styleObj.fillColor) {
        style.fill = new Fill({
            color: styleObj.fillColor
        });
    }
    return new Style(style);
};
export default Layer
